programming4us
           
 
 
Windows

Windows Azure Storage : Message Operations (part 1) - Put Message

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/29/2010 2:35:19 PM
Messages support several operations, as listed in Table 1.
Table 1. Messages Operations
OperationDescription
Put MessageEn-queues a message at the end of the specified queue. The message can't be more than 8KB in size.
Get MessagesDequeues one or more messages from the front of the specified queue. The maximum number of messages that can be retrieved in a single call is 32. The messages received are marked invisible until the visibilitytimeout property of the message expires. The default visibilitytimeout is 30 seconds, and the maximum value is 2 hours.
Peek MessagesReads one or more messages from the front of the specified queue. This method doesn't alter the visibilitytimeout property of a message, so the messages are visible to other applications at the same time.
Delete MessageDeletes the specified message from the queue. The Queue service marks the message for deletion, and the message is deleted during the next garbage-collection cycle. The delete operation requires the MessageId and PopReceipt of the message to be passed to the Queue service.
Clear MessagesDeletes all messages from the specified queue.

Table 2 lists some of the important characteristics of the message operations.

Table 2. Message Operations Characterstics
OperationHTTP VerbCloud URIDevelopment Storage URIHTTP VersionPermissions
Put MessagePOSThttp://<accountname>.queue.core.windows.net/<queuename>/messageshttp://127.0.0.1:10001/<devstorageaccount>/<queuename>/messagesHTTP/1.1Only the account owner can call this operation.
Get MessagesGEThttp://<accountname>.queue.core.windows.net/<queuename>/messageshttp://127.0.0.1:10001/<devstorageaccount>/<queuename>/messagesHTTP/1.1Only the account owner can call this operation.
Peek MessagesGEThttp://<accountname>.queue.core.windows.net/<queuename>/messages?peekonly=truehttp://127.0.0.1:10001/<devstorageaccount>/<queuename>/messages?peekonly=trueHTTP/1.1Only the account owner can call this operation.
Delete MessageDELETEhttp://<accountname>.queue.core.windows.net/<queuename>/<messageid>?popreceipt=[popreceiptvalue]http://127.0.0.1:10001/<devstorageaccount>/<queuename>/<messageid>?popreceipt=[popreceiptvalue]HTTP/1.1Only the account owner can call this operation.
Clear MessagesDELETEhttp://<accountname>.queue.core.windows.net/<queuename>/messageshttp://127.0.0.1:10000/<devstorageaccount>/<queuename>/messagesHTTP/1.1Only the account owner can call this operation.

The <account name> is the storage account name in the cloud, and the <devstorageaccount> is the development storage account. The <queue name> is the name of the queue in which messages are stored. The following sections discuss some of the operations from Table 5-9 in detail. Even though the operations are different, the programming concepts behind them are similar. To keep the book at a conceptual level, I discuss just the Put Message and Get Messages operations. By studying these two operations in detail, you can understand the programming concepts behind all the message operations. The Windows Azure Storage Operations application included with this chapter's source code contains implementations of most of the message operations.

1. Put Message

The Put Message operation en-queues (puts) a message at the end of the queue. The URI of a Put Message operation is of the format account name>.queue.core.windows.net/<queue name>/messages. You can send a message with size up to 8KB. To send larger files, you can save the message as a blob and send the URI of the blob to the queue. The body of the message while sending can be text or binary, but it should support inclusion in an XML body with UTF-8 encoding. This is because a message received from the queue is always returned in Base64-encoded format within an XML response body. You see this in the Get Messages operation. The URI for the Put Message operation supports an additional optional parameter, listed in Table 3.

Table 3. Put Message URI Parameter
ParameterDescriptionExample
messagettlThis is an integer value of seconds representing the time-to-live for a message in the queue before it's retrieved or deleted. The default and the maximum value for messagettl is 7 days, after which the message is garbage-collected.account name>.queue.core.windows.net/<queuename>/messages?messagettl=60

The Put Message REST request looks like Listing 1.

Example 1. Put Message REST Request
POST /myfirstazurequeue/messages?messagettl=120&timeout=30 HTTP/1.1
x-ms-date: Thu, 18 Jun 2009 05:52:00 GMT
Authorization: SharedKey proazurestorage:Ahv5yhR9xOrHiMTnq3fBcaBKL8KeUFQ3r
Host: proazurestorage.queue.core.windows.net
Content-Length: 84
Expect: 100-continue

<QueueMessage>
<MessageText>bXlmaXJzdGF6dXJlbWVzc2FnZQ==</MessageText>
</QueueMessage>

In Listing 1, a string message "myfirstazuremessage" is sent to the queue named myfirstazurequeue. The time-to-live seconds for the message is 120, which means if the message isn't received or deleted by an application within 120 seconds in the queue, the message will be marked for deletion and won't be visible to any applications. The request body consists of the message content wrapped in the <QueueMessage> element. Note that the content of the message within the <MessageText /> element is in Base64-encoded format. Listing 2 shows the response from the Queue service.

Example 2. Put Message REST Response
HTTP/1.1 201 Created
Server: Queue Service Version 1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: e724cc82-3d21-4253-9317-3b3964374be7
Date: Thu, 18 Jun 2009 05:53:32 GMT
Content-Length: 0

As shown in Listing 2, the Queue service responds with an HTTP/1.1 201 Created status code for a successful Put Message operation. Figure 1 shows the working of the Put Message operation in the Windows Azure Storage Operations application.

Figure 1. Put Message in Windows Azure Storage Operations.exe

As illustrated in Figure 1, you can send a text message using the Windows Azure Storage Operations application. The steps for sending a message to a queue are as follows:

  1. Create a new queue (called myfirstazurequeue).

  2. Select the new queue from the Queues List Box in the Accounts section.

  3. Add some text to the Message Body text box in the Queues section.

  4. Select the Put Message operation from the Operations text box.

  5. Make sure the Queue Name text box is populated with the selected queue name.

  6. Optionally, you can specify the time-to-live in the "Time to live (secs)" text box.

  7. Click the Execute button to execute the Put Message operation.

The WindowsAzureStorage.cs file in the Windows Azure Storage Operations project consists of a PutMessage() method, as shown in Listing 3.

Example 3. PutMessage() Method in WindowsAzureStorage.cs
private void PutMessage()
{
string messageBody = string.Empty;
if (txtMessageBody.Text.Length > 0)
{
messageBody = txtMessageBody.Text;

}
else
{
messageBody = String.Format
("Message from Windows Azure Storage Operations",
System.Guid.NewGuid().ToString("N"));
}
int ttlsecs = 300;
if(txtTimeTolive.Text.Length > 0)
{
ttlsecs = int.Parse(txtTimeTolive.Text);
}
if (StorageHelper.PutMessage(txtQueueName.Text, new
Microsoft.Samples.ServiceHosting.StorageClient.Message(messageBody), ttlsecs))
{
statusLabel.Text = String.Format
("Message {0} sent successfully to queue {1}", messageBody, txtQueueName.Text);

}
}


As shown in Listing 3, the PutMessage() method calls the PutMessage() operation on the WindowsAzureStorageHelper (StorageHelper object). The message body and the time-to-live values are parsed appropriately from the server controls and passed as parameters to the method. If you don't enter a message in the Message Body text box, the application automatically creates a default message for you. Figure 2 shows the sequence of Put Message operation from the application to the Queue service as it passes through various assemblies and objects.

Figure 2. Put Message sequence diagram

As shown in Figure 2, the Windows Azure Storage Operations application calls the PutMessage() method on the WindowsStorageHelper object in the ProAzureCommonLib.dll. The WindowsStorageHelper object calls the GetQueue() method on the QueueStorage object to get an instance of the MessageQueue object. The WindowsStorageHelper object then calls the PutMessage() method on the MessageQueue object. The PutMessage() method of the MessageQueue object creates the REST message request and sends it synchronously to the Queue service. It uses the System.Net.HttpWebRequest to send the REST message over HTTP. Upon the success of the operation, the Queue service returns an HTTP status code: HTTP/1.1 201 Created. The PutMessage() method translates the HTTP code into true for success and false for failure. The Boolean value is passed all the way to the Windows Azure Storage Operations application as a return parameter of the PutMessage() method.

Other -----------------
- Windows Azure Storage : Queue Operations
- Windows Azure Storage : Account Operations
- Windows 7 : Removing an Icon from Control Panel
- Windows 7 : Showing Only Specified Control Panel Icons
- Windows 7 : Easier Access to Control Panel
- Windows 7 : Understanding Control Panel Files
- Windows 7 : Reviewing the Control Panel Icons
- Windows 7 : Touring the Control Panel Window
- Windows 7 : Reviewing Event Viewer Logs
- Windows 7 : Checking for Updates and Security Patchess
- Windows 7 : Backing Up Your Files
- Windows 7 : Preparing for Trouble
- Windows 7 : Defragmenting Your Hard Disk
- Windows 7 : Deleting Unnecessary Files
- Windows 7 : Checking Free Disk Space
- Windows 7 : Checking Your Hard Disk for Errors
- Windows Azure : Understanding Message Operations
- Windows Azure : Understanding Queue Operations
- Windows Azure Queue Overview
- Tuning Windows 7’s Performance : Optimizing Virtual Memory
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us